package com.itheima.demo02;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamClass07 {
    public static void main(String[] args) {
        Map<String,Integer> map = Map.ofEntries(Map.entry("张三",23),Map.entry("李四",24));
        //method1(map);
        //method2(map);
        method3(map);
    }

    private static void method3(Map<String, Integer> map) {
        map.values().forEach(s -> System.out.println(s));
        map.values().stream().collect(Collectors.toList()).stream().forEach(s -> System.out.println(s));
    }

    private static void method2(Map<String, Integer> map) {
        Stream<String> stream2 = map.keySet().stream();
        stream2.filter(s -> s.startsWith("张三"))
                .collect(Collectors.toList())
                .stream().forEach(s -> System.out.println(s));
    }

    private static void method1(Map<String, Integer> map) {
        Stream<Map.Entry<String, Integer>> stream1 = map.entrySet().stream();
        Map<String, Integer> collect = stream1.filter(s -> s.getValue() == 24)
                .collect(Collectors.toMap(s -> s.getKey(), s -> s.getValue()));
        collect.entrySet().stream().forEach(s -> System.out.println(s));
    }
}
